import request from '../../utils/request.js'
import {isPermission} from "../../utils/utils.js";

// 查询学生
export function listCourse(data) {
    // 学生权限
    if (isPermission(0)) {
        return request({
            url: '/course/studentlist',
            method: 'get',
            params: data
        })
    }
    if (isPermission(2)) {
        return request({
            url: '/course/teacherlist',
            method: 'get',
            params: data
        })
    }
}

// 查询章节
export function listCourseChapter(id) {
    return request({
        url: '/course/list/chapters/' + id,
        method: 'get'
    })
}

// 查询章节
export function listCourseSonChapter(id) {
    return request({
        url: '/course/list/sonchapters/video/' + id,
        method: 'get'
    })
}


// 查询任务
export function listTask(id) {
    return request({
        url: '/course/list/doing/task/' + id,
        method: 'get'
    })
}

// 查询课程中的资源
export function listResource(id, data) {
    return request({
        url: '/course/list/resources/' + id,
        method: 'get',
        params: data
    })
}

// 查询分班
export function listCourseClass(id) {
    return request({
        url: '/course/list/class/' + id,
        method: 'get'
    })
}

// 新增分班
export function insertCourseClass(id, data) {
    return request({
        url: '/course/insert/class/' + id,
        method: 'post',
        params: data
    })
}

// 查询课程中所有学生
export function listCourseStudent(id) {
    return request({
        url: '/course/list/class/student/' + id,
        method: 'get',
    })
}

//邀请学生
export function inviteStudent(data) {
    return request({
        url: '/course/invite/studentclass',
        method: 'post',
        data: data
    })
}


//查看进行中考试
export function listOngoingExams(id) {
    return request({
        url: '/course/list/ongoing/exams/' + id,
        method: 'get',
    })
}

//查看结束考试
export function listEndExams(id) {
    return request({
        url: '/course/list/end/exams/' + id,
        method: 'get',
    })
}

// 查询课程中进行中的作业
export function listOngoingAssignment(id) {
    return request({
        url: '/course/list/ongoing/assignments/' + id,
        method: 'get',
    })
}

//查询课程中结束的作业
export function listEndAssignment(id) {
    return request({
        url: '/course/list/end/assignments/' + id,
        method: 'get',
    })
}

//  删除班级
export function deleteCourseClass(id) {
    return request({
        url: '/course/delete/class/' + id,
        method: 'delete',
    })
}

// 删除学生
export function deleteCourseStudent(studentId, courseId) {
    return request({
        url: '/course/delete/studentclass/' + studentId + "/" + courseId,
        method: 'delete',
    })
}

// 移动班级
export function moveCourseClass(data) {
    return request({
        url: '/course/update/studentclass',
        method: 'put',
        data: data
    })
}

// 上传资源
export function uploadResource(courseId, data) {
    // console.log(data)
    return request({
        url: '/course/upload/resources/' + courseId,
        method: 'post',
        data: data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}


// 删除资源
export function deleteResource(ids) {
    return request({
        url: '/course/delete/resources',
        method: 'delete',
        data: ids
    })
}


// 获取当前章节信息
export function getOneCourseSonChapter(id) {
    return request({
        url: '/course/get/sonchapter/video/' + id,
        method: 'get',
    })
}


//获取当前作业信息
export function getAssignment(id) {
    return request({
        url: '/course/get/assignment/' + id,
        method: 'get',
    })
}

// 获取当前作业所有题目
export function listAssignmentQuestions(id) {
    return request({
        url: '/course/list/assignment/questions/' + id,
        method: 'get',
    })
}

//获取题目选项
export function getAssignmentQuestionOptions(id) {
    return request({
        url: '/course/get/assignment/question/options/' + id,
        method: 'get',
    })
}

//增加大章节
export function insertChapter(data) {
    return request({
        url: '/course/insert/chapters',
        method: 'post',
        data: data
    })
}

//增加小章节
export function insertSonChapter(data) {
    return request({
        url: '/course/insert/sonchapters/video',
        method: 'post',
        data: data
    })
}

//上传视频
export function uploadSonChapterVideo(id, data) {
    return request({
        url: '/course/upload/sonchapters/video/' + id,
        method: 'post',
        data: data,
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 修改大章节
export function updateChapter(data) {
    return request({
        url: '/course/update/chapters',
        method: 'put',
        data: data
    })
}

//修改小章节
export function updateSonChapter(data) {
    return request({
        url: '/course/update/sonchapters/video',
        method: 'put',
        data: data
    })
}

//删除小章节
export function deleteSonChapter(id) {
    return request({
        url: '/course/delete/sonchapters/video/' + id,
        method: 'delete',
    })
}

//增加作业信息
export function insertAssignment(data) {
    return request({
        url: '/course/insert/assignments',
        method: 'post',
        data: data
    })
}


//增加作业题目
export function insertAssignmentQuestions(id, data) {
    return request({
        url: '/course/insert/list/assignment/questions/' + id,
        method: 'post',
        data: data
    })
}

//增加作业选项
export function insertAssignmentQuestionOptions(data) {
    return request({
        url: '/course/insert/list/assignment/question/options',
        method: 'post',
        data: data
    })
}

// 增加考试信息
export function insertExam(data) {
    return request({
        url: '/course/insert/exams',
        method: 'post',
        data: data
    })
}

// 新增考试题目信息
export function insertExamQuestions(id, data) {
    return request({
        url: '/course/insert/list/exams/questions/' + id,
        method: 'post',
        data: data
    })
}

//新增考试题目选项
export function insertExamQuestionOptions(data) {
    return request({
        url: '/course/insert/list/exams/questions/options',
        method: 'post',
        data: data
    })
}


//获取考试信息
export function getExam(id) {
    return request({
        url: '/course/get/exams/' + id,
        method: 'get',
    })
}

//获取考试题目信息
export function listExamQuestions(id) {
    return request({
        url: '/course/list/exams/questions/' + id,
        method: 'get',
    })
}

//获取考试题目选项
export function getExamQuestionOptions(id) {
    return request({
        url: '/course/get/exams/question/options/' + id,
        method: 'get',
    })
}

// 添加任务
export function insertTask(data) {
    return request({
        url: '/course/insert/task',
        method: 'post',
        data: data
    })
}


// 添加讨论
export function insertDiscussion(data) {
    return request({
        url: '/course/insert/task/discuss',
        method: 'post',
        data: data
    })
}

// 添加随堂练习id-->taskId
export function insertClassPractice(id, data) {
    return request({
        url: '/course/insert/task/questions/' + id,
        method: 'post',
        data: data
    })
}

// 添加随堂练习的选项
export function insertClassPracticeOptions(data) {
    return request({
        url: '/course/insert/task/question/options',
        method: 'post',
        data: data
    })
}


// 添加问卷题目
export function insertQuestionnaireQuestions(id, data) {
    return request({
        url: '/course/insert/task/questionnaire/' + id,
        method: 'post',
        data: data
    })
}

// 添加问卷选项
export function insertQuestionnaireQuestionOptions(data) {
    return request({
        url: '/course/insert/task/questionnaire/options',
        method: 'post',
        data: data
    })
}

// 查询任务信息
export function getTask(id) {
    return request({
        url: '/course/get/task/' + id,
        method: 'get',
    })
}

// 查询随堂练习题目信息
export function listClassPracticeQuestions(id) {
    return request({
        url: '/course/list/task/questions/' + id,
        method: 'get',
    })
}

//获取当前题目的选项
export function getClassPracticeQuestionOptions(id) {
    return request({
        url: '/course/get/task/question/options/' + id,
        method: 'get',
    })
}

// 查询问卷题目信息
export function listQuestionnaireQuestions(id) {
    return request({
        url: '/course/list/task/questionnaire/' + id,
        method: 'get',
    })
}

//获取当前问卷题目的选项
export function getQuestionnaireQuestionOptions(id) {
    return request({
        url: '/course/get/task/questionnaire/options/' + id,
        method: 'get',
    })
}

// 获取讨论题目
export function getDiscussion(id) {
    return request({
        url: '/course/get/task/discuss/' + id,
        method: 'get',
    })
}

// 获取讨论回复
export function listDiscussionReview(id) {
    return request({
        url: '/course/list/task/discuss/review/' + id,
        method: 'get',
    })
}

// 进行父级回复
export function insertParentReview(data) {
    return request({
        url: '/course/insert/task/discuss/review',
        method: 'post',
        data: data
    })
}

// 添加章节检测
export function insertChapterTestQuestions(id,data) {
    return request({
        url: '/course/insert/sonchapters/test/questions/' + id,
        method: 'post',
        data: data
    })
}

// 添加章节检测的选项
export function insertChapterTestQuestionOptions(data) {
    return request({
        url: '/course/insert/sonchapters/test/questions/options',
        method: 'post',
        data: data
    })
}

// 获取章节检测的题目
export function listChapterTestQuestions(id) {
    return request({
        url: '/course/list/sonchapters/test/questions/' + id,
        method: 'get',
    })
}

// 获取题目选项
export function getChapterTestQuestionOptions(id) {
    return request({
        url: '/course/get/sonchapters/test/questions/options/' + id,
        method: 'get',
    })
}

//新增签到
export function insertSignIn(data) {
    return request({
        url: '/course/insert/task/signin',
        method: 'post',
        data: data
    })
}

// 查询签到
export function getSignIn(id) {
    return request({
        url: '/course/get/task/signin/' + id,
        method: 'get',
    })
}

// 进行签到
export function studentSignIn(data) {
    return request({
        url: '/course/insert/task/student/signin',
        method: 'post',
        data: data
    })
}

// 人脸比对
export function faceCompare(formData) {
    return request({
        headers:{ "Content-Type":"multipart/form-data" },
        url: '/aiChat/faceCompare',
        method: 'post',
        data: formData
    })
}

// 提交答案
export function submitAnswer(answer,id) {
    return request({
        url: '/course/post/exams/submitAnswer?answer=' + answer + '&id=' + id,
        method: 'post',
    })
}

// 刷新状态
export function updateState() {
    return request({
        url: '/course/update/state',
        method: 'put'
    })
}

// 新增课程
export function insertCourse(data) {
    return request({
        url: '/course/insert',
        method: 'post',
        data: data
    })
}

// 更新课程人数
export function updateCourseNumber(id,number) {
    return request({
        url: '/course/update/number/' + id,
        method: 'put',
        params: number
    })
}

// 学生加入课程
export function studentJoinCourse(invite) {
    return request({
        url: '/course/join/studentclass',
        method: 'post',
        params:invite

    })
}

//学生提交考试记录
export function submitExam(id) {
    return request({
        url: '/course/submit/exams/' + id,
        method: 'post'
    })
}

// 学生是否参加过这次考试
export function isJoinExam(id) {
    return request({
        url: '/course/get/exams/finish/' + id,
        method: 'get'
    })
}

// 提交答案
export function submitAssignmentAnswer(answer) {
    return request({
        url: '/course/post/assignment/submitAnswer',
        method: 'post',
        data:answer
    })
}

// 学生提交过作业记录
export function submitAssignment(id) {
    return request({
        url: '/course/submit/assignment/' + id,
        method: 'post'
    })
}

//获取课程详细西信息
export function getCourse(id) {
    return request({
        url: '/course/get/' + id,
        method: 'get',
    })
}

// 学生是否提交过作业
export function isSubmitAssignment(id) {
    return request({
        url: '/course/get/assignment/finish/' + id,
        method: 'get'
    })
}

//获取学生的答案
export function getStudentAssignmentAnswer(id) {
    return request({
        url: '/course/list/assignment/student/answer/' + id,
        method: 'get'
    })
}

//提交章节检测答案
export function submitChapter(id) {
    return request({
        url: '/course/submit/test/' + id,
        method: 'post'
    })
}

// 提交答案
export function submitChapterAnswer(answer) {
    return request({
        url: '/course/insert/test/submitAnswer',
        method: 'post',
        data:answer
    })
}

//检测是否已经提交过答案
export function isSubmitChapterTest(id) {
    return request({
        url: '/course/get/test/finish/' + id,
        method: 'get'
    })
}

//获取学生的答案
export function getStudentChapterAnswer(id) {
    return request({
        url: '/course/list/test/student/answer/' + id,
        method: 'get'
    })
}

//获取完成列表
export function getFinishList(id) {
    return request({
        url: '/course/list/test/isSubmit/' + id,
        method: 'get'
    })
}